import service from '@/utils/request'

export const useDeviceApi = (id: string) => {
  return service.get('/gps/device/' + id)
}
export const useDeviceSaveSubmitApi = (dataForm: any,update) => {
  if(update){
    return service.post('/gps/device/save', dataForm)
  }
  return service.put('/gps/device/update', dataForm)
}

export const submitSettingsApi = ({imeis,amount,simAmount}) => {
  return service.post('/gps/device/device/annual',imeis,{
    params:{
      amount,
      simAmount
    }
  })
}

/**
 * 获取全部设备状态信息
 * @param data
 */
export const useDeviceStatusInfoApi = (data: { onlyVideo: boolean }) => {
  return service.get('/gps/device/status', {
    params: data
  })
}
/**
 * 获取设备列表
 * @param data
 */
export const useDeviceListApi = (data: any) => {
  if (data.connectionStatus === 'total') {
    delete data.connectionStatus
  }
  if (data.connectionStatus === 'favor') {
    delete data.connectionStatus
    data.favor = true
  }
  return service.get('/gps/device/page/list', {
    params: data
  })
}
export const useDeviceInfoApi = (id: string) => {
  return service.get('/gps/device/info1/' + id)
}
export const useDeviceAndStatusApi = (id: string) => {
  return service.get('/gps/device/info/' + id)
}

export function useSearchImeiApi(imei: string) {
  return service.get('/gps/device/listByImei', {
    params: {
      imei
    }
  })
}

export function useSearchImeiApi2(imei: string) {
  return service.get('/gps/device/listByImei2', {
    params: {
      imei
    }
  })
}
// 获取用户所有的设备型号
export function getProductByUser() {
  return service.get('/gps/product/ownerByUser')
}
//获取设备分组列表
export const getdeviceGroupingApi = (id) => {
  return service.get('/gps/group/listByDept?deptId=' + id)
}
export const deviceListPageApi = (data) => {
  return service.get('gps/device/listPage', {
    params: data
  })
}

//转移提交
export const transmitChangesApi = (data) => {
  return service.post('gps/device/transfer', data)
}

//分组列表
export const getlistGroupingApi = (id: string) => {
  return service.get('gps/group/list?deptId=' + id)
}

export const groupSubmissions = (data) => {
  if (!data.id){
    return service.post('/gps/group/save', data)
  }
    return service.put('/gps/group/update', data)
}

export function deleteGrouping(id) {
  return service.delete(`/gps/group/delete/${id}`)
}

export function followSave(imei) {
  return service.post('gps/device/favor?imei=' + imei)
}
// export const useImeiListApi = () => {
//   return service.get('gps/device/list')
// }

export function clearAttribute(imei) {
  return service.put('gps/device/clearAttribute', null, {
    params: {
      imei
    }
  })
}
